/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.desktop.paneles;

import com.google.gson.Gson;
import java.awt.event.ItemEvent;
import java.util.Calendar;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JRadioButton;

/**
 *
 * @author Alejandro
 */
public class ModificarActividad extends javax.swing.JPanel {

    /**
     * Creates new form ModificarActividad
     */
    private AdmEvent padre;
    private String noActividades = "no hay actividades en el evento";
    private DefaultListModel lista = new DefaultListModel();
    private String actividadModificando;
    public ModificarActividad(AdmEvent father) {
        initComponents();
        padre = father;
        jLabel47.setText(Temporal.evento);//seteo del nombre del evento en el titulo
        jComboBox5.removeAllItems();
        if(hayActividades())
        {
            this.listaActividades();//se listan las actividades
            actividadModificando = jComboBox5.getItemAt(0).toString();
        }
        else
        {
            jComboBox5.addItem(noActividades);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel46 = new javax.swing.JLabel();
        jLabel45 = new javax.swing.JLabel();
        jComboBox5 = new javax.swing.JComboBox();
        jLabel47 = new javax.swing.JLabel();

        setMinimumSize(new java.awt.Dimension(602, 548));
        setPreferredSize(new java.awt.Dimension(602, 548));

        jButton3.setText("Aceptar");
        jButton3.setMaximumSize(new java.awt.Dimension(130, 25));
        jButton3.setMinimumSize(new java.awt.Dimension(130, 25));
        jButton3.setPreferredSize(new java.awt.Dimension(130, 25));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Cancelar");
        jButton4.setMaximumSize(new java.awt.Dimension(130, 25));
        jButton4.setMinimumSize(new java.awt.Dimension(130, 25));
        jButton4.setPreferredSize(new java.awt.Dimension(130, 25));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel46.setText("Seleccione actividad que desea modificar:");

        jLabel45.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel45.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel45.setText("Usted esta modificando");
        jLabel45.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox5ActionPerformed(evt);
            }
        });

        jLabel47.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel47.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel47.setText("\"nombre del Evento\"");
        jLabel47.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel46, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jComboBox5, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addGap(61, 61, 61)
                .addComponent(jLabel45, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel47, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                .addGap(57, 57, 57))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel45)
                    .addComponent(jLabel47))
                .addGap(18, 18, 18)
                .addComponent(jLabel46)
                .addGap(11, 11, 11)
                .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 416, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        //boton aceptar
        if(jComboBox5.getSelectedItem().toString().equals(noActividades))
        {
            JOptionPane.showMessageDialog(this,"No hay actividades para modificar","Error", JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            padre.jSplitPane3.setRightComponent(new ModActividad(padre,jComboBox5.getSelectedItem().toString()));
        }
    }//GEN-LAST:event_jButton3ActionPerformed
        
    private void jComboBox5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox5ActionPerformed

    }//GEN-LAST:event_jComboBox5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        //boton cancelar
        padre.jSplitPane3.setRightComponent(new com.desktop.mensajes.BienActividad(Temporal.evento));
    }//GEN-LAST:event_jButton4ActionPerformed
    
    private void listaActividades()
    {
        Gson gson = new Gson();
        String [] actividades = gson.fromJson(listarActividades(Temporal.evento), String[].class);
        if(actividades !=null)
        {
            for(String a:actividades)
            {
                this.jComboBox5.addItem(a);
            }
            jComboBox5.setSelectedIndex(0);
        }
        else
        {
                this.jComboBox5.addItem(noActividades);
        }
    }
    
    private boolean hayActividades()
    {
        Gson gson = new Gson();
        String [] actividades = gson.fromJson(listarActividades(Temporal.evento), String[].class);
        if(actividades!=null)
        {
            return true;
        }
        return false;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    // End of variables declaration//GEN-END:variables

    private static String listarActividades(java.lang.String evento) {
        com.webservice.servicios.Gestor_Service service = new com.webservice.servicios.Gestor_Service();
        com.webservice.servicios.Gestor port = service.getGestorPort();
        return port.listarActividades(evento);
    }

}
